from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-16 14:02:25.408498
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 16, Apr, 2022
Time: 14:02:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.9772
Nobs: 628.000 HQIC: -49.3666
Log likelihood: 7648.92 FPE: 2.83770e-22
AIC: -49.6139 Det(Omega_mle): 2.46160e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.331225 0.063208 5.240 0.000
L1.Burgenland 0.106025 0.039770 2.666 0.008
L1.Kärnten -0.110633 0.020834 -5.310 0.000
L1.Niederösterreich 0.195125 0.083113 2.348 0.019
L1.Oberösterreich 0.119875 0.081950 1.463 0.144
L1.Salzburg 0.259356 0.042185 6.148 0.000
L1.Steiermark 0.044161 0.055544 0.795 0.427
L1.Tirol 0.104938 0.044951 2.334 0.020
L1.Vorarlberg -0.065069 0.039677 -1.640 0.101
L1.Wien 0.021297 0.072854 0.292 0.770
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044243 0.135339 0.327 0.744
L1.Burgenland -0.036472 0.085153 -0.428 0.668
L1.Kärnten 0.041646 0.044609 0.934 0.351
L1.Niederösterreich -0.200305 0.177958 -1.126 0.260
L1.Oberösterreich 0.454954 0.175467 2.593 0.010
L1.Salzburg 0.283672 0.090326 3.141 0.002
L1.Steiermark 0.110485 0.118929 0.929 0.353
L1.Tirol 0.307236 0.096248 3.192 0.001
L1.Vorarlberg 0.027107 0.084954 0.319 0.750
L1.Wien -0.024162 0.155991 -0.155 0.877
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189575 0.032324 5.865 0.000
L1.Burgenland 0.089107 0.020337 4.381 0.000
L1.Kärnten -0.007486 0.010654 -0.703 0.482
L1.Niederösterreich 0.243910 0.042502 5.739 0.000
L1.Oberösterreich 0.160570 0.041908 3.832 0.000
L1.Salzburg 0.040244 0.021573 1.865 0.062
L1.Steiermark 0.027308 0.028404 0.961 0.336
L1.Tirol 0.083673 0.022987 3.640 0.000
L1.Vorarlberg 0.055009 0.020290 2.711 0.007
L1.Wien 0.119721 0.037256 3.213 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109747 0.032352 3.392 0.001
L1.Burgenland 0.042888 0.020355 2.107 0.035
L1.Kärnten -0.013303 0.010663 -1.248 0.212
L1.Niederösterreich 0.173801 0.042539 4.086 0.000
L1.Oberösterreich 0.333687 0.041944 7.956 0.000
L1.Salzburg 0.101122 0.021591 4.683 0.000
L1.Steiermark 0.112821 0.028429 3.969 0.000
L1.Tirol 0.091427 0.023007 3.974 0.000
L1.Vorarlberg 0.060949 0.020307 3.001 0.003
L1.Wien -0.013801 0.037288 -0.370 0.711
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110381 0.060598 1.822 0.069
L1.Burgenland -0.045389 0.038127 -1.190 0.234
L1.Kärnten -0.045795 0.019974 -2.293 0.022
L1.Niederösterreich 0.137908 0.079681 1.731 0.083
L1.Oberösterreich 0.163885 0.078566 2.086 0.037
L1.Salzburg 0.283628 0.040443 7.013 0.000
L1.Steiermark 0.059544 0.053250 1.118 0.263
L1.Tirol 0.160544 0.043095 3.725 0.000
L1.Vorarlberg 0.098549 0.038038 2.591 0.010
L1.Wien 0.078995 0.069845 1.131 0.258
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054493 0.047426 1.149 0.251
L1.Burgenland 0.026371 0.029840 0.884 0.377
L1.Kärnten 0.052919 0.015632 3.385 0.001
L1.Niederösterreich 0.196558 0.062360 3.152 0.002
L1.Oberösterreich 0.331384 0.061488 5.389 0.000
L1.Salzburg 0.037173 0.031652 1.174 0.240
L1.Steiermark 0.011356 0.041675 0.272 0.785
L1.Tirol 0.121634 0.033727 3.606 0.000
L1.Vorarlberg 0.066923 0.029770 2.248 0.025
L1.Wien 0.102088 0.054663 1.868 0.062
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167416 0.057010 2.937 0.003
L1.Burgenland 0.005630 0.035870 0.157 0.875
L1.Kärnten -0.065730 0.018791 -3.498 0.000
L1.Niederösterreich -0.102235 0.074963 -1.364 0.173
L1.Oberösterreich 0.206937 0.073913 2.800 0.005
L1.Salzburg 0.055244 0.038049 1.452 0.147
L1.Steiermark 0.245416 0.050097 4.899 0.000
L1.Tirol 0.501330 0.040543 12.365 0.000
L1.Vorarlberg 0.064314 0.035786 1.797 0.072
L1.Wien -0.075895 0.065709 -1.155 0.248
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146412 0.063230 2.316 0.021
L1.Burgenland -0.001215 0.039783 -0.031 0.976
L1.Kärnten 0.062557 0.020841 3.002 0.003
L1.Niederösterreich 0.170777 0.083141 2.054 0.040
L1.Oberösterreich -0.053333 0.081977 -0.651 0.515
L1.Salzburg 0.207535 0.042200 4.918 0.000
L1.Steiermark 0.139547 0.055563 2.512 0.012
L1.Tirol 0.057933 0.044967 1.288 0.198
L1.Vorarlberg 0.148753 0.039690 3.748 0.000
L1.Wien 0.123361 0.072878 1.693 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.379400 0.037282 10.177 0.000
L1.Burgenland -0.002934 0.023457 -0.125 0.900
L1.Kärnten -0.020666 0.012288 -1.682 0.093
L1.Niederösterreich 0.207262 0.049022 4.228 0.000
L1.Oberösterreich 0.230192 0.048336 4.762 0.000
L1.Salzburg 0.038249 0.024882 1.537 0.124
L1.Steiermark -0.013397 0.032761 -0.409 0.683
L1.Tirol 0.089093 0.026513 3.360 0.001
L1.Vorarlberg 0.053051 0.023402 2.267 0.023
L1.Wien 0.042181 0.042971 0.982 0.326
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036712 0.111038 0.173225 0.139848 0.101658 0.081588 0.037262 0.211116
Kärnten 0.036712 1.000000 -0.024379 0.131936 0.050881 0.086812 0.443714 -0.065645 0.090170
Niederösterreich 0.111038 -0.024379 1.000000 0.317119 0.125463 0.277552 0.069700 0.155675 0.293125
Oberösterreich 0.173225 0.131936 0.317119 1.000000 0.216929 0.299343 0.167870 0.139361 0.241261
Salzburg 0.139848 0.050881 0.125463 0.216929 1.000000 0.126108 0.093782 0.107461 0.127035
Steiermark 0.101658 0.086812 0.277552 0.299343 0.126108 1.000000 0.136200 0.110283 0.039416
Tirol 0.081588 0.443714 0.069700 0.167870 0.093782 0.136200 1.000000 0.066225 0.152704
Vorarlberg 0.037262 -0.065645 0.155675 0.139361 0.107461 0.110283 0.066225 1.000000 -0.002885
Wien 0.211116 0.090170 0.293125 0.241261 0.127035 0.039416 0.152704 -0.002885 1.000000